package com.scs.application.modules.msg.sender;

import lombok.Getter;

import java.util.Date;

/**
 */
public class MessageSenderContext {

    private final static ThreadLocal<MessageSenderContext> currentLocal = new InheritableThreadLocal<>();

    @Getter
    private Date beginTime;

    public static MessageSenderContext getOrNew() {
        if (currentLocal.get() == null) {
            currentLocal.set(new MessageSenderContext());
        }
        return currentLocal.get();
    }

    /**
     * 清除线程变量
     */
    public static void clear() {
        if (currentLocal.get() != null) {
            /*currentLocal.remove();*/
            currentLocal.set(null);
        }
    }

    public void begin(){
        this.beginTime = new Date();
    }

}
